<?php

namespace App\Model;

/**
 * 配置-模型
 */
class Config extends Model
{
    protected ?string $table = 'config';

    protected array $fillable = [
        'key', 'value'
    ];

    /**
     * 获取配置
     * @param $key
     * @return string
     */
    public static function getConfig($key): string
    {
        return self::where('key', $key)->value('value') ?? '';
    }

    /**
     * 设置配置
     * @param $key
     * @param $value
     * @return bool
     */
    public static function setConfig($key, $value): bool
    {
        return (bool)self::updateOrCreate(['key' => $key], ['value' => $value]);
    }
}
